package com.vic;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Objects;

@SpringBootApplication
@Slf4j
public class VicApp {
    public static ConfigurableApplicationContext context = null;

    public static void main(String[] args) {
        context = SpringApplication.run(VicApp.class, args);
        printAddress();
    }

    private static void printAddress() {
        try {
            InetAddress addr = InetAddress.getLocalHost();
            String hostAddress = addr.getHostAddress();
            String port = "8080";
            String setPort = context.getBean(Environment.class).getProperty("server.port");
            if (Objects.nonNull(setPort)) {
                port = setPort;
            }
            String address = "http://" + hostAddress + ":" + port + "/route/index";
            log.info("请访问主页地址：{}", address);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
}
